Research
Security News
Threat Actor Exposes Playbook for Exploiting npm to Build Blockchain-Powered Botnets
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.
content-hash
Advanced tools
simple tool to encode/decode content hash for EIP 1577 compliant ENS Resolvers
The content-hash npm package is used to generate content hashes for various types of content. This can be useful for caching, versioning, and ensuring data integrity.
Generate Hash for a String
This feature allows you to generate a hash for a given string. The hash can be used to uniquely identify the content of the string.
const contentHash = require('content-hash');
const hash = contentHash('Hello, World!');
console.log(hash);
Generate Hash for a Buffer
This feature allows you to generate a hash for a Buffer object. This is useful for binary data or files.
const contentHash = require('content-hash');
const buffer = Buffer.from('Hello, World!');
const hash = contentHash(buffer);
console.log(hash);
Generate Hash for a File
This feature allows you to generate a hash for a file by reading its contents into a Buffer and then hashing it. This is useful for ensuring file integrity.
const fs = require('fs');
const contentHash = require('content-hash');
const filePath = 'path/to/your/file.txt';
const fileBuffer = fs.readFileSync(filePath);
const hash = contentHash(fileBuffer);
console.log(hash);
The hasha package is a versatile hashing library that supports multiple algorithms like MD5, SHA-1, and SHA-256. It is similar to content-hash but offers more flexibility in terms of hashing algorithms.
The crypto package is a built-in Node.js module that provides cryptographic functionality, including hashing. It is more low-level compared to content-hash but offers extensive features for cryptographic operations.
The object-hash package is designed to hash JavaScript objects. It is similar to content-hash but specifically optimized for object hashing, making it useful for generating unique identifiers for complex data structures.
This is a simple package made for encoding and decoding content hashes as specified in the EIP 1577. This package will be useful for every Ethereum developer wanting to interact with EIP 1577 compliant ENS resolvers.
Here you can find a live demo of this package.
swarm-ns
ipfs-ns
ipns-ns
utf-8
.You can see the full list of codec supported here
$> npm install content-hash
$> git clone https://github.com/pldespaigne/content-hash.git
$> cd content-hash
$> npm install
For browser only usage, installation is not required.
Import the module in order to use it :
const contentHash = require('content-hash')
<!--From CDN-->
<script type="text/javascript" src="https://unpkg.com/content-hash/dist/index.js"></script>
<!--From local module-->
<script type="text/javascript" src="path/to/dist/index.js"></script>
To rebuild the browser version of the package run
npm run build
into the root folder. Don't forget to also runnpm run lint
andnpm test
before building !
All hex string inputs can be prefixed with
0x
, but it's not mandatory.
⚠️ All outputs are NOT prefixed with
0x
This function takes a content hash as a hex string and returns the decoded content as a string.
const encoded = 'e3010170122029f2d17be6139079dc48696d1f582a8530eb9805b561eda517e22a892c7e3f1f'
const content = contentHash.decode(encoded)
// 'QmRAQB6YaCyidP37UdDnjFY5vQuiBrcqdyoW1CuDgwxkD4'
This function takes an IPFS address as a base58 encoded string and returns the encoded content hash as a hex string.
this function just call
contentHash.encode()
under the hood
const ipfsHash = 'QmRAQB6YaCyidP37UdDnjFY5vQuiBrcqdyoW1CuDgwxkD4'
const contentH = contentHash.fromIpfs(ipfsHash)
// 'e3010170122029f2d17be6139079dc48696d1f582a8530eb9805b561eda517e22a892c7e3f1f'
This function takes a Swarm address as a hex string and returns the encoded content hash as a hex string.
this function just call
contentHash.encode()
under the hood
const swarmHash = 'd1de9994b4d039f6548d191eb26786769f580809256b4685ef316805265ea162'
const contentH = contentHash.fromSwarm(swarmHash)
// 'e40101701b20d1de9994b4d039f6548d191eb26786769f580809256b4685ef316805265ea162'
This function takes a supported codec as a string and a value as a string and returns coresponding content hash as a hex string.
const onion = 'zqktlwi4fecvo6ri'
contentHash.encode('onion', onion);
// 'bc037a716b746c776934666563766f367269'
This function takes a content hash as a hex string and returns the codec as a hex string.
const encoded = 'e40101701b20d1de9994b4d039f6548d191eb26786769f580809256b4685ef316805265ea162'
const codec = contentHash.getCodec(encoded) // 'swarm-ns'
codec === 'ipfs-ns' // false
This object contain the following helpers functions :
const ipfs = 'QmYwAPJzv5CZsnA625s3Xf2nemtYgPpHdWEz79ojWnPbdG'
const cidV1 = contentHash.helpers.cidV0ToV1Base32(ipfs)
// 'bafybeibj6lixxzqtsb45ysdjnupvqkufgdvzqbnvmhw2kf7cfkesy7r7d4'
For any questions, discussions, bug report, or whatever I will be happy to answer through the issues or on my twitter 😁. PR (with tests) are also welcome !
This project is licensed under the ISC License, you can find it here.
Note that the dependencies may have a different License
FAQs
simple tool to encode/decode content hash for EIP 1577 compliant ENS Resolvers
The npm package content-hash receives a total of 190,665 weekly downloads. As such, content-hash popularity was classified as popular.
We found that content-hash demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.
Security News
NVD’s backlog surpasses 20,000 CVEs as analysis slows and NIST announces new system updates to address ongoing delays.
Security News
Research
A malicious npm package disguised as a WhatsApp client is exploiting authentication flows with a remote kill switch to exfiltrate data and destroy files.